const tokens = {
  admin: {
    token: 'admin-token'
  },
  editor: {
    token: 'editor-token'
  }
}

const users = {
  'admin-token': {
    roles: ['admin'],
    introduction: 'I am a super administrator',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Super Admin'
  },
  'editor-token': {
    roles: ['editor'],
    introduction: 'I am an editor',
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
    name: 'Normal Editor'
  }
}

const routers = {
  'admin-token': [{
    'id': 9,
    'name': '产品管理',
    'type': 2,
    'parentId': 8,
    'path': '/sys/pro',
    'component': '/index/index.vue',
    'wrapComponent': 1,
    'params': 'a=b&b=c',
    'orderNum': 2,
    'icon': 'icon6',
    'target': 1,
    'keepAlive': false,
    'permissions': null,
    'isDisabled': false,
    'isHide': false
  }, {
    'id': 2,
    'name': '用户管理',
    'type': 2,
    'parentId': 1,
    'path': '/sys/user',
    'component': '/basic/user/index.vue',
    'wrapComponent': 0,
    'params': '',
    'orderNum': 2,
    'icon': 'icon2',
    'target': 1,
    'keepAlive': false,
    'permissions': null,
    'isDisabled': false,
    'isHide': false
  }, {
    'id': 1,
    'name': '系统管理',
    'type': 1,
    'parentId': 0,
    'path': '',
    'component': null,
    'wrapComponent': null,
    'params': 'a=b&b=c',
    'orderNum': 1,
    'icon': 'icon1',
    'target': null,
    'keepAlive': null,
    'permissions': null,
    'isDisabled': null,
    'isHide': false
  }, {
    'id': 3,
    'name': '用户新增删除按钮',
    'type': 3,
    'parentId': 2,
    'path': '',
    'component': null,
    'wrapComponent': null,
    'params': null,
    'orderNum': 3,
    'icon': null,
    'target': null,
    'keepAlive': null,
    'permissions': 'sys:user:add,sys:user:delete',
    'isDisabled': null,
    'isHide': null
  }, {
    'id': 8,
    'name': '综合管理',
    'type': 1,
    'parentId': 0,
    'path': '',
    'component': null,
    'wrapComponent': null,
    'params': null,
    'orderNum': 1,
    'icon': 'icon5',
    'target': null,
    'keepAlive': null,
    'permissions': null,
    'isDisabled': null,
    'isHide': false
  }, {
    'id': 4,
    'name': '角色管理',
    'type': 2,
    'parentId': 1,
    'path': '/sys/role',
    'component': '/basic/role/index.vue',
    'wrapComponent': 0,
    'params': 'a=b&b=c',
    'orderNum': 2,
    'icon': 'icon3',
    'target': 1,
    'keepAlive': false,
    'permissions': null,
    'isDisabled': false,
    'isHide': false
  }, {
    'id': 5,
    'name': '角色新增删除按钮',
    'type': 3,
    'parentId': 4,
    'path': '',
    'component': null,
    'wrapComponent': null,
    'params': null,
    'orderNum': 3,
    'icon': null,
    'target': null,
    'keepAlive': null,
    'permissions': 'sys:role:add,sys:role:delete',
    'isDisabled': null,
    'isHide': null
  }, {
    'id': 6,
    'name': '菜单管理',
    'type': 2,
    'parentId': 1,
    'path': '/sys/menu',
    'component': '/basic/menu/index.vue',
    'wrapComponent': 0,
    'params': 'a=b&b=c',
    'orderNum': 2,
    'icon': 'icon4',
    'target': 1,
    'keepAlive': false,
    'permissions': null,
    'isDisabled': false,
    'isHide': false
  }, {
    'id': 7,
    'name': '菜单新增删除按钮',
    'type': 3,
    'parentId': 6,
    'path': '',
    'component': null,
    'wrapComponent': null,
    'params': null,
    'orderNum': 3,
    'icon': null,
    'target': null,
    'keepAlive': null,
    'permissions': 'sys:menu:add,sys:menu:delete',
    'isDisabled': null,
    'isHide': null
  }, {
    'id': 14,
    'name': '租户管理',
    'type': 2,
    'parentId': 1,
    'path': '/sys/tenant',
    'component': '/basic/tenant/index.vue',
    'wrapComponent': 0,
    'params': 'a=b&b=c',
    'orderNum': 2,
    'icon': 'icon3',
    'target': 1,
    'keepAlive': false,
    'permissions': null,
    'isDisabled': false,
    'isHide': false
  }, {
    'id': 15,
    'name': '字典管理',
    'type': 2,
    'parentId': 1,
    'path': '/sys/dict',
    'component': '/basic/dict/index.vue',
    'wrapComponent': 0,
    'params': 'a=b&b=c',
    'orderNum': 2,
    'icon': 'icon3',
    'target': 1,
    'keepAlive': false,
    'permissions': null,
    'isDisabled': false,
    'isHide': false
  }, {
    'id': 10,
    'name': '目录即菜单',
    'type': 2,
    'parentId': 0,
    'path': '/sys/inner',
    'component': '/index/index.vue',
    'wrapComponent': 1,
    'params': null,
    'orderNum': 1,
    'icon': 'icon5',
    'target': 1,
    'keepAlive': null,
    'permissions': null,
    'isDisabled': null,
    'isHide': false
  }, {
    'id': 11,
    'name': '外部跳转',
    'type': 2,
    'parentId': 0,
    'path': 'http://www.163.com',
    'component': '',
    'wrapComponent': 1,
    'params': null,
    'orderNum': 1,
    'icon': 'icon5',
    'target': 2,
    'keepAlive': null,
    'permissions': null,
    'isDisabled': null,
    'isHide': false
  }, {
    'id': 12,
    'name': '内部跳转',
    'type': 2,
    'parentId': 0,
    'path': 'https://www.baidu.com',
    'component': '/iframe/index.vue',
    'wrapComponent': 1,
    'params': '/iframe/baidu',
    'orderNum': 1,
    'icon': 'icon5',
    'target': 1,
    'keepAlive': null,
    'permissions': null,
    'isDisabled': null,
    'isHide': false
  }, {
    'id': 13,
    'name': '跳转',
    'type': 2,
    'parentId': 0,
    'path': 'https://www.qq.com',
    'component': '/iframe/index.vue',
    'wrapComponent': 1,
    'params': '/iframe/qq',
    'orderNum': 1,
    'icon': 'icon5',
    'target': 1,
    'keepAlive': null,
    'permissions': null,
    'isDisabled': null,
    'isHide': false
  }],
  'editor-token': [{
    'id': 1,
    'name': '系统管理',
    'type': 1,
    'parentId': 0,
    'path': '',
    'component': null,
    'wrapComponent': null,
    'params': 'a=b&b=c',
    'orderNum': 1,
    'icon': 'icon1',
    'target': null,
    'keepAlive': null,
    'permissions': null,
    'isDisabled': null,
    'isHide': false
  }, {
    'id': 2,
    'name': '用户管理',
    'type': 2,
    'parentId': 1,
    'path': '/sys/user',
    'component': '/index/index.vue',
    'wrapComponent': 0,
    'params': 'a=b&b=c',
    'orderNum': 2,
    'icon': 'icon2',
    'target': 1,
    'keepAlive': false,
    'permissions': null,
    'isDisabled': false,
    'isHide': false
  }, {
    'id': 4,
    'name': '角色管理',
    'type': 2,
    'parentId': 1,
    'path': '/sys/role',
    'component': '/index/index.vue',
    'wrapComponent': 0,
    'params': 'a=b&b=c',
    'orderNum': 2,
    'icon': 'icon3',
    'target': 1,
    'keepAlive': false,
    'permissions': null,
    'isDisabled': false,
    'isHide': false
  }, {
    'id': 8,
    'name': '其他管理',
    'type': 1,
    'parentId': 0,
    'path': '',
    'component': null,
    'wrapComponent': null,
    'params': null,
    'orderNum': 1,
    'icon': 'icon5',
    'target': null,
    'keepAlive': null,
    'permissions': null,
    'isDisabled': null,
    'isHide': false
  }, {
    'id': 9,
    'name': '产品管理',
    'type': 2,
    'parentId': 8,
    'path': '/sys/pro',
    'component': '/index/index.vue',
    'wrapComponent': 1,
    'params': 'a=b&b=c',
    'orderNum': 2,
    'icon': 'icon6',
    'target': 1,
    'keepAlive': false,
    'permissions': null,
    'isDisabled': false,
    'isHide': false
  }]
}

export default [
  // user login
  {
    url: '/user/login',
    type: 'post',
    response: config => {
      const { username } = config.body
      const token = tokens[username]

      // mock error
      if (!token) {
        return {
          code: 401,
          message: 'Account and password are incorrect.'
        }
      }

      return {
        code: 0,
        data: token
      }
    }
  },

  // get user info
  {
    url: '/user/info\.*',
    type: 'get',
    response: config => {
      const { token } = config.query
      const info = users[token]

      // mock error
      if (!info) {
        return {
          code: 401,
          message: 'Login failed, unable to get user details.'
        }
      }

      return {
        code: 0,
        data: info
      }
    }
  },

  // user logout
  {
    url: '/user/logout',
    type: 'post',
    response: _ => {
      return {
        code: 0,
        data: 'success'
      }
    }
  },

  // get router
  {
    url: '/sys/menu/nav',
    type: 'get',
    response: config => {
      const {
        token
      } = config.query
      const data = routers[token]

      // mock error
      if (!token) {
        return {
          code: 401,
          msg: '未授权，可能是没有传入token 或 token 失效'
        }
      }

      return {
        code: 0,
        msg: '请求成功',
        data
      }
    }
  }
]
